<template>
	<view class="main">
		<view class="main-box">
			<view class="box">
				<view class="item" v-for="(item, index) in tabList" :key="index" @click="clickItem(item, index)">
					<view class="item-box">
						<view class="icon" :class="{ 'ac-b': index == current }">
							<image :src="item.icon.s ? item.icon.sPath : item.icon.path" mode="aspectFill"></image>
						</view>
						<view class="name" :class="{ 'ac-c': index == current }">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref, reactive, watch } from 'vue';
const tabList = ref([
	{ name: '首页', type: 1, icon: { path: '/static/ac-home.png', sPath: '/static/home.png', s: true } },
	{ name: '我的', type: 2, icon: { path: '/static/ac-mine.png', sPath: '/static/mine.png', s: false } }
]);

const props = defineProps({
	v: Number
});

watch(props.v, () => {
	console.log(props.v, '变了');
});

const emit = defineEmits(['sel']);
const current = ref(0);

if (props.v == 0) {
	current.value = 0;
}

const clickItem = (item, index) => {
	current.value = index;
	tabList.value.forEach((item, idx) => (item.icon.s = idx === index));
	emit('sel', current.value);
};
</script>

<style lang="scss" scoped>
.ac-b {
	background: linear-gradient(0deg, #f49a5e 0%, #fe4f56 100%) !important;
}

.ac-c {
	color: #fb4e47 !important;
}

.main {
	width: 100%;
	height: 166rpx;
	background: #ffffff;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 1;
	.main-box {
		.box {
			margin-top: -14rpx;
			padding: 0 161rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.item:first-child {
				margin-right: 253rpx;
			}
			.item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.item-box {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					.icon {
						margin-bottom: 20rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						width: 80rpx;
						height: 80rpx;
						background-color: transparent;
						border-radius: 50%;
						image {
							width: 41rpx;
							height: 37rpx;
						}
					}
					.name {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 22rpx;
						color: #777;
					}
				}
			}
		}
	}
}
</style>
